#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{

    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    rand = qrand()%7;

    setWindowFlag(Qt::FramelessWindowHint);
    this->resize(1600,1000);
    setWindowTitle("compressBox");
    createCompressor();
    this->setWindowFlags(Qt::WindowMinimizeButtonHint|Qt::WindowCloseButtonHint);
}

MainWindow::~MainWindow(){

}


bool MainWindow::createCompressor(){

    compressor->resize(1600,1000);
    compressor->move(0,0);

    QPushButton* pb = new QPushButton("compressor",compressor);
    pb->resize(1600,1000);
    pb->move(0,0);

    QObject::connect(pb,&QPushButton::clicked,new compressWindow(this,&pixMap),&compressWindow::setShow);


    QGraphicsOpacityEffect* op = new QGraphicsOpacityEffect();
    pb->setGraphicsEffect(op);
    op->setOpacity(0);

    return true;
}

void MainWindow::paintEvent(QPaintEvent(*)){
    switch (rand) {
    case 1:
        if(!image->load(QString("D:/VS2019 Files/toolBox/toolBox/image/1.jpg")))
            QMessageBox::warning(this,"wrong","wrong in opening image file.");
        break;
    case 2:
        if(!image->load(QString("D:/VS2019 Files/toolBox/toolBox/image/2.jpg")))
            QMessageBox::warning(this,"wrong","wrong in opening image file.");
        break;
    case 3:
        if(!image->load(QString("D:/VS2019 Files/toolBox/toolBox/image/3.jpg")))
            QMessageBox::warning(this,"wrong","wrong in opening image file.");
        break;
    case 4:
        if(!image->load(QString("D:/VS2019 Files/toolBox/toolBox/image/4.jpg")))
            QMessageBox::warning(this,"wrong","wrong in opening image file.");
        break;
    case 5:
        if(!image->load(QString("D:/VS2019 Files/toolBox/toolBox/image/5.jpg")))
            QMessageBox::warning(this,"wrong","wrong in opening image file.");
        break;
    case 6:
        if(!image->load(QString("D:/VS2019 Files/toolBox/toolBox/image/6.jpg")))
            QMessageBox::warning(this,"wrong","wrong in opening image file.");
        break;
    case 0:
        if(!image->load(QString("D:/VS2019 Files/toolBox/toolBox/image/7.jpg")))
            QMessageBox::warning(this,"wrong","wrong in opening image file.");
        break;
    }
    QPainter painter(this);
    pixMap = QPixmap::fromImage(*image);
    painter.drawPixmap(rect(),pixMap,QRect());
}

void MainWindow::dropEvent(QDropEvent*event)    //放下事件
{
    const QMimeData*qm=event->mimeData();//获取MIMEData	//依据文件名导入文件即可
}
